package com.example.core.arch.interceptor;

import com.example.core.arch.baseData.CodeConstants;
import com.example.core.service.helper.RedisHelper;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class UserCheckInterceptor implements HandlerInterceptor {

    @Resource
    private RedisHelper redisHelper;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        String cookie = request.getHeader(CodeConstants.COOKIE);
        String systemCode = request.getHeader(CodeConstants.SYSTEM_CODE);
        String token = request.getHeader(CodeConstants.TOKEN);
        if (checkSystem(systemCode, token)) {
            return true;
        }
        return checkCookie(response, cookie);
    }

    private boolean checkSystem(String systemCode, String token) {
        return true;
    }

    private boolean checkCookie(HttpServletResponse response, String cookie) throws IOException {
        return true;
    }
}

